#include "mainwindow.h"
#include "ui_mainwindow.h"

/**
 * @brief 主窗口构造函数，初始化UI和页面
 * @param parent 父窗口指针
 */
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_stackedWidget = new QStackedWidget(this);
    setCentralWidget(m_stackedWidget);

    initPages();
    initConnections();
}

/**
 * @brief 主窗口析构函数，释放资源
 */
MainWindow::~MainWindow()
{
    delete ui;
}

/**
 * @brief 初始化所有页面并添加到页面容器
 */
void MainWindow::initPages()
{
    // 仅框架，无具体实现
    m_loginPage = new LoginPage();
    m_registerPage = new RegisterPage();
    m_profilePage = new PersonalProfilePage();
    m_profileEditPage = new ProfileEditPage();
    m_pwdChangePage = new PasswordChangePage();
    m_friendListPage = new FriendListPage();
    m_addFriendPage = new AddFriendPage();
    m_friendReqPage = new FriendRequestPage();
    m_friendDetailPage = new FriendDetailPage();
    m_groupListPage = new GroupListPage();
    m_createGroupPage = new CreateGroupPage();
    m_joinGroupPage = new JoinGroupPage();
    m_groupDetailPage = new GroupDetailPage();
    m_settingsPage = new SettingsPage();
    m_conversationPage = new ConversationPage();

    // 添加页面到容器
    m_stackedWidget->addWidget(m_loginPage);
    m_stackedWidget->addWidget(m_registerPage);
    m_stackedWidget->addWidget(m_profilePage);
    m_stackedWidget->addWidget(m_profileEditPage);
    m_stackedWidget->addWidget(m_pwdChangePage);
    m_stackedWidget->addWidget(m_friendListPage);
    m_stackedWidget->addWidget(m_addFriendPage);
    m_stackedWidget->addWidget(m_friendReqPage);
    m_stackedWidget->addWidget(m_friendDetailPage);
    m_stackedWidget->addWidget(m_groupListPage);
    m_stackedWidget->addWidget(m_createGroupPage);
    m_stackedWidget->addWidget(m_joinGroupPage);
    m_stackedWidget->addWidget(m_groupDetailPage);
    m_stackedWidget->addWidget(m_settingsPage);
    m_stackedWidget->addWidget(m_conversationPage);

    // 默认显示登录页面
    m_stackedWidget->setCurrentWidget(m_loginPage);
}

/**
 * @brief 初始化所有信号槽连接
 */
void MainWindow::initConnections()
{
    // 仅框架，无具体实现
}

/**
 * @brief 处理登录成功事件，切换到主页面
 * @param userId 用户ID
 * @param username 用户名
 */
void MainWindow::onLoginSuccess(const QString &userId, const QString &username)
{
    // 仅框架，无具体实现
    m_currentUserId = userId;
    m_currentUsername = username;
}

/**
 * @brief 处理退出登录事件，返回登录页面
 */
void MainWindow::onLogout()
{
    // 仅框架，无具体实现
    m_currentUserId.clear();
    m_currentUsername.clear();
}
